package com.h3c.nem.controller;

import com.eos.common.constant.StatusCodeEnum;
import com.eos.common.util.Result;
import com.github.pagehelper.PageInfo;
import com.h3c.nem.dto.PageQueryDTO;
import com.h3c.nem.entity.TbCareNoticeSetting;
import com.h3c.nem.service.impl.TbCareNoticeSettingServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 新员工关怀通知配置
 *
 * @author z22968
 * @date 2022-06-08 17:05
 */
@CrossOrigin
@RestController
@RequestMapping("/careNoticeSetting")
public class TbCareNoticeSettingController {
    @Resource
    TbCareNoticeSettingServiceImpl tbCareNoticeSettingService;

    /**
     * 添加
     *
     * @param tbCareNoticeSetting
     * @return com.eos.common.util.Result
     * @author z22968
     * @date 2022-06-09 11:16
     */
    @PostMapping
    public Result insert(@RequestBody TbCareNoticeSetting tbCareNoticeSetting) {
        tbCareNoticeSettingService.insert(tbCareNoticeSetting);
        return new Result(true, StatusCodeEnum.ADD_SUCCESS);
    }

    /**
     * 更新
     *
     * @param tbCareNoticeSetting
     * @return com.eos.common.util.Result
     * @author z22968
     * @date 2022-06-09 11:17
     */
    @PutMapping
    public Result update(@RequestBody TbCareNoticeSetting tbCareNoticeSetting) {
        tbCareNoticeSettingService.update(tbCareNoticeSetting);
        return new Result(true, StatusCodeEnum.UPDATE_SUCCESS);
    }

    /**
     * 分页获取数据
     *
     * @param pageQuery
     * @return com.eos.common.util.Result
     * @author z22968
     * @date 2022-06-28 19:10
     */
    @PostMapping("/page")
    public Result selectByPage(@RequestBody PageQueryDTO<TbCareNoticeSetting> pageQuery) {
        if (pageQuery.getCondition() == null) {
            pageQuery.setCondition(new TbCareNoticeSetting());
        }
        PageInfo<TbCareNoticeSetting> data = tbCareNoticeSettingService.selectByPage(pageQuery);
        return new Result(true, StatusCodeEnum.SEARCH_SUCCESS, data);
    }

    /**
     * 根据类型查询数据
     *
     * @param type
     * @return java.util.List<com.h3c.nem.entity.TbCareNoticeSetting>
     * @author z22968
     * @date 2022-06-28 11:31
     */
    @GetMapping("/{type}")
    public Result selectByType(@PathVariable(value = "type") String type) {
        // TODO 修改成使用枚举
        List<TbCareNoticeSetting> data = tbCareNoticeSettingService.selectByType(type);
        return new Result(true, StatusCodeEnum.SEARCH_SUCCESS, data);
    }
    /**
     * 删除配置
     *
     * @param id
     * @return com.eos.common.util.Result
     * @author z22968
     * @date 2022-06-29 17:42
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable(value = "id") String id) {
        // 删除
        tbCareNoticeSettingService.deleteById(id);
        return new Result(true, StatusCodeEnum.REMVOE_SUCCESS);
    }

}

